package cn.edu.leetcode.其他;

public class 猜数字大小 {
    public static void main(String[] args) {
        System.out.println(guessNumber(2126753390));
    }

    public static int guessNumber(int n) {
        int min = 1, max = n;
        int guessnum = min + (max - min)/2;
        while(guess(guessnum) != 0){
            if (guess(guessnum)<0){
                max = guessnum -1;
            }else{
                min = guessnum +1;
            }
            guessnum = min + (max - min)/2;
        }
        return guessnum;
    }

    public static int guess(int guessnum) {
        int num = 1702766719;
        if (guessnum == num) {
            return 0;
        }else if (num < guessnum){
            return -1;
        }else {
            return 1;
        }
    }
}
